<template>
    <div class="category_add">
        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item :label="label.name">
                <el-input v-model="form.name"></el-input>
            </el-form-item>
            <el-form-item :label="label.parent">
                <el-select v-model="form.parent" placeholder="">
                    <el-option v-for="(pc,index) in pcates" :label="pc.name" :value="pc.id" :key="index"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item :label="label.desc">
                <el-input type="textarea" v-model="form.desc"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="create()">立即创建</el-button>
                <el-button type="primary" @click="upload()">导入目录</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import {log} from '@/assets/js/util.js'
    export default{
        name: 'category_add',
        data () {
            return {
                msg: 'category_add',
                pcates:[],
                label:{
                    name:'目录名称',
                    parent:'父级目录',
                    desc:'目录描述',
                },
                form:{
                    name:'',
                    parent:'',
                    desc:'',
                },
            }
        },
        methods:{
            create:function () {

            },
            upload:function () {

            },
            init:function () {
                var url = server_url+'/api/categorys';
                this.$http.jsonp(url, {}, {
                    headers: {},
                    emulateJSON: true
                }).then(function(response) {
                    this.pcates = response.data.data
                }, function(response) {
                    log(response)
                });
            }
        },
        mounted:function () {
            this.init()
        }
    }
</script>

<style>
    .category_add{

    }
    .el-select{
        width: 100% !important;
    }
</style>